//
//  JGMeController.m
//  JGRider
//
//  Created by 单启志 on 2018/1/25.
//  Copyright © 2018年 ffq. All rights reserved.
//

#import "JGMeController.h"
#import "JGMeCell.h"
#import "JGMeModel.h"
#import "JGMeHeadView.h"
#import "JGMessageController.h"

#import "JGRankingOrderController.h"//接单排行
#import "JGGoodsOrderController.h"  //好评排行
#import "JGMyBadOrderController.h"  //我的差评

@interface JGMeController ()<UITableViewDelegate,UITableViewDataSource,JGMeHeadViewDelegate>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)JGMeHeadView *headView;
@property(nonatomic,strong)NSArray<JGMeModel*> *datas;
@property(nonatomic,strong)UIImageView *topImageView;
@end

@implementation JGMeController
static NSString *cellId=@"mecell";
-(void)viewDidLoad{
    [super viewDidLoad];
    //self.title=@"我的";
    self.lmj_navgationBar.alpha=1;
    self.datas=[JGMeModel models];

    [self.view addSubview:self.topImageView];
    [self.view addSubview:self.tableView];
}

#pragma mark - 头view delegate
//我的接单
-(void)headViewMyOrderBtnEvent{
    NSLog(@"我的接单");
}
//接单排名
-(void)headViewRankingOrderBtnEvent{
     NSLog(@"接单排名");
    JGRankingOrderController *vc=[[JGRankingOrderController alloc]init];
    JGpushViewController(vc);
}
//好评排行
-(void)headViewGoodsOrderBtnEvent{
     NSLog(@"好评排行");
    JGGoodsOrderController *vc=[[JGGoodsOrderController alloc]init];
    JGpushViewController(vc);
}
//我的差评
-(void)headViewMyBadOrderBtnEvent{
     NSLog(@"我的差评");
    JGMyBadOrderController *vc=[[JGMyBadOrderController alloc]init];
    JGpushViewController(vc);
}

#pragma mark - tableview delegate

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGPoint offset= scrollView.contentOffset;
    NSLog(@"AAA%.2f",offset.y);

    if (offset.y<0) {
        self.topImageView.height=AdaptedHeight(139)-offset.y;
        self.topImageView.width=JGScreenW-offset.y;
        self.topImageView.mj_x=offset.y/2.0;
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
   _headView=[[[NSBundle mainBundle]loadNibNamed:@"JGMeHeadView" owner:nil options:nil]lastObject];
    _headView.delegate=self;
    return _headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return AdaptedHeight(268);
   // return 278.0;//AdaptedHeight(278);// 278;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.datas.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return AdaptedWidth(52);
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    JGMeCell *cell=[tableView dequeueReusableCellWithIdentifier:cellId];
    cell.model=self.datas[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NSLog(@"%ld",indexPath.row);
  JGpushViewController([[self.datas[indexPath.row].destVc alloc]init]);

}

#pragma mark - override

-(UIColor *)lmjNavigationBackgroundColor:(LMJNavigationBar *)navigationBar{

    return [UIColor clearColor];
}

-(UIImage *)lmjNavigationBarLeftButtonImage:(UIButton *)leftButton navigationBar:(LMJNavigationBar *)navigationBar{

    return [UIImage imageNamed:@""];
}

-(UIImage *)lmjNavigationBarRightButtonImage:(UIButton *)leftButton navigationBar:(LMJNavigationBar *)navigationBar{

    return [UIImage imageNamed:@"notice"];
}

-(void)rightButtonEvent:(UIButton *)sender navigationBar:(LMJNavigationBar *)navigationBar{

    JGpushViewController([[JGMessageController alloc]init]);
}

#pragma mark - getter setter
-(UITableView *)tableView{

    if (_tableView==nil) {
        _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, JGScreenW, JGScreenH) style:UITableViewStyleGrouped];
        _tableView.backgroundColor=[UIColor clearColor];
        //_tableView.bounces=NO;
        _tableView.showsVerticalScrollIndicator=NO;
        _tableView.delegate=self;
        _tableView.dataSource=self;
        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([JGMeCell class]) bundle:nil] forCellReuseIdentifier:cellId];
    _tableView.separatorStyle=UITableViewCellSelectionStyleNone;
    }
    return _tableView;
}

-(UIImageView *)topImageView{
    if (!_topImageView) {
        _topImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, JGScreenW, AdaptedHeight(139))];
        _topImageView.image=[UIImage imageNamed:@"mine_background"];
    }
    return _topImageView;
}
@end
